package com.jt.demo52.SpringAop;;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;


@Component
@Aspect
@Order(2)
public class SpringAop {
    @Pointcut("bean(userServiceImpl)")
    public void Amazed(){
    }

    @Before(value = "Amazed()")
    public void before(JoinPoint joinPoint) {
        Class<?> aClass = joinPoint.getTarget().getClass();
        String declaringTypeName = joinPoint.getSignature().getDeclaringTypeName();
        String name = joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        System.out.println("对象类型"+aClass);
        System.out.println("对象名称"+declaringTypeName);
        System.out.println("目标名称"+name);
        System.out.println("参数"+ Arrays.toString(args));
        System.out.println("前置通知");
    }

    @AfterReturning(value = "Amazed()",returning = "object")
    public void afterReturning(Object object){
        System.out.println("后置通知");
        System.out.println("后置通知接受 返回值："+object);
    }

    @AfterThrowing(value = "Amazed()",throwing = "ex")
    public void AfterThrowing(Exception ex){

        System.out.println("有错误"+ex.getMessage());
    }
    @After(value = "Amazed()")
    public void After(){
        System.out.println("最终通知");
    }

    @Around(value = "Amazed()")
    public Object Around(ProceedingJoinPoint joinPoint)throws Throwable{
        System.out.println("环绕！");
        Object proceed = joinPoint.proceed();
        System.out.println("环绕！");
            return proceed;
    }
}
